FROM php:7.1-apache

RUN sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
RUN sed -i 's|security.debian.org|mirrors.ustc.edu.cn/debian-security|g' /etc/apt/sources.list

# APT 自动安装 PHP 相关的依赖包,如需其他依赖包在此添加
RUN apt-get update \
    && apt-get install -y \
        vim \
        libmcrypt-dev \
        libz-dev \
        git \
        wget \
        libpcre3-dev \

    # 官方 PHP 镜像内置命令，安装 PHP 依赖
    && docker-php-ext-install \
        mcrypt \
        mbstring \
        pdo_mysql \
        zip \
        bcmath \
    # 用完包管理器后安排打扫卫生可以显著的减少镜像大小
    && apt-get clean \
    && apt-get autoclean \
    && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \

    # 安装 Composer，此物是 PHP 用来管理依赖关系的工具
    && curl -sS https://install.phpcomposer.com/installer | php -- --install-dir=/usr/local/bin --filename=composer

# RUN composer config -g repo.packagist composer https://packagist.phpcomposer.com

# 安装扩展php redis
RUN pecl install -o -f  redis \
    &&  rm -rf /tmp/pear \
    &&  docker-php-ext-enable redis 

# 安装扩展php opcache
RUN docker-php-ext-install opcache
COPY ./opcache.ini /usr/local/etc/php/conf.d/opcache.ini

#安装gd
RUN apt-get update && apt-get install -y \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libmcrypt-dev \
        libpng-dev \
    && docker-php-ext-install -j$(nproc) iconv mcrypt \
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
    && docker-php-ext-install -j$(nproc) gd

#安装npm
ENV NVM_DIR /root/.nvm
ENV NODE_VERSION 6.11.4

RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.1/install.sh | bash && \
        . $NVM_DIR/nvm.sh && \
        nvm install ${NODE_VERSION} && \
        nvm use ${NODE_VERSION} && \
        nvm alias ${NODE_VERSION} 
ADD ./src/eboss.tar.gz /tmp
RUN cd /tmp/eboss \
    && composer install \
    && . ~/.bashrc \
    && npm install \
    && npm run prod


# 开启 URL 重写模块
# 配置默认放置 App 的目录
RUN a2enmod rewrite \
    && mkdir -p /app \
    && rm -fr /var/www/html \
    && ln -s /app/public /var/www/html

#安装ndoejs
# RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.1/install.sh | bash && \
#         . $NVM_DIR/nvm.sh && \
#         nvm install stable && \
#         nvm use stable && \
#         nvm alias stable


WORKDIR /app

# 预先加载 Composer 包依赖，优化 Docker 构建镜像的速度
#COPY ./composer.json /app/
#COPY ./composer.lock /app/
#RUN composer install  --no-autoloader --no-scripts

# 复制代码到 App 目录
# COPY . /app
# RUN mv /app/.env.testing02 /app/.env

# 修改目录权限
# RUN composer install \
#     && chown -R www-data:www-data /app \
#     && chmod -R 0777 /app/storage

